<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" +
            request.getServerPort() + path + "/";
%>
<html>
<head>
    <title>$Title$</title>
</head>
<body>
<c:if test="${empty subwayList}">
    <c:redirect url ="subway?opr=list" />
</c:if>
<div style="width: 600px;margin: auto">
    <h1>地铁线路信息列表</h1>
    <a href="add.jsp">添加地铁路线</a>
    <table border="1" cellpadding="5" cellspacing="0">
        <thead>
        <tr>
            <th>项目名称</th>
            <th>始发站</th>
            <th>终点站</th>
            <th>途经站点数</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${subwayList}" var="subway">
            <tr>
                <td><a href="subway?opr=getone&id=${subway.id}">${subway.subwayname}</a></td>
                <td>${subway.startstation}</td>
                <td>${subway.endstation}</td>
                <td>${subway.stationnum}</td>
                <td>
                    <a href="subway?opr=mgetone&id=${subway.id}">修改</a>
                    <a href="javascript:(0)" onclick="confirmDel(${subway.id})">删除</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <script type="text/javascript" src="js/jquery-3.3.1.js"></script>
    <script type="text/javascript">
        $(function () {
           $("tr:odd").css("background","#9c9c9c")
        });
        function confirmDel(id) {
            if(confirm("确认要删除吗？")){
                location.href = "subway?opr=del&id="+id;
            }else {
                alert("您取消了操作")
            }
        }
    </script>
</div>
</body>
</html>
